#include <iostream>
#include <vector>
using namespace std;

class line{
public:
	int w;
	int b;
	int r;
	line(void){
		w=0,b=0;r=0;
	}
	int tored(void){
		return w+b;
	}
	int towhite(void){
		return r+b;
	}
	int toblue(void){
		return w+r;
	}
};

int main(void){
	vector<line> flag;
	int n,m,sum,min=100000;
	char input;
	cin>>n>>m;
	for(int i=0;i<n;i++){
		line temp;
		for(int j=0;j<m;j++){
			sign:
			cin>>input;
			switch(input){
				case 'W':
				temp.w++;
				break;
				case 'B':
				temp.b++;
				break;
				case 'R':
				temp.r++;
				break;
				default:
				goto sign;
			}
		}
		flag.push_back(temp);
	}

	for(int i=0;i<n-2;i++){		//i:end of white
		for(int j=0;j<n-1;j++){	//j:end of blue
			sum=0;
			for(int k=0;k<n;k++){
				if(k<=i)sum+=flag[k].towhite();
				if(k>i&&k<=j)sum+=flag[k].toblue();
				if(k>j)sum+=flag[k].tored();
			}
			if(min>sum)min=sum;
		}
	}
	cout<<min;
	return 0;
}
